﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Lor;

namespace ExpenseSystem.Fether
{
    public class UnitFetcher : NormalFetcher<UnitModel>,IDetailFetcher<UnitModel>
    {
        public UnitModel GetByCode( long site, string code, out string message)
        {
            IList<UnitModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("Code", code).And(Restrain.Eq("Avaliable", true)));
            if (result.Count > 0)
                return result.First();
            return null;
        }


        public IList<UnitModel> ListByMainId( long site, long mainId, out string message,out int rows)
        {
            IList<UnitModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("UnitGroupId", mainId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
    }
}
